package com.cskaoyan.config;

import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.mgt.DefaultWebSessionStorageEvaluator;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
/**     跨域保持sessionId不变
 * @Description:
 * @Author: cuiweiguo#
 * @Date: 2022/5/10 10:43
 * @Param: :
 * @return: :
 **/
@Component
public class CustomShiroSessionManager  extends DefaultWebSessionManager {
  private  static  final  String HEADER="X-CskaoyanMarket-Admin-Token";
    private static final String MARKET_HEADER = "X-CskaoyanMarket-Token";
    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String sessionId = httpServletRequest.getHeader(MARKET_HEADER);
        if (sessionId == null) {
            sessionId = httpServletRequest.getHeader(HEADER);
        }

        if (sessionId != null && !"".equals(sessionId.trim())) {
            return sessionId;
        }
        return super.getSessionId(request,response);
    }
}
